<template>
	<view>
		<view class="mt30 bgw text-lg p30">
			<view @tap="times()" class="list">
				<view>营业日期 :</view>
				<view v-if="time1 == '请选择营业日期'" style="color: #808080;">{{ time1 }}</view>
				<view v-if="time1 != '请选择营业日期'">{{ time1 }}</view>
				<image class="go" src="../../static/image/go1.png" mode=""></image>
			</view>
			<view @tap="times2()" class="list">
				<view>开始时间 :</view>
				<view v-if="time2 == '请选择开始时间'" style="color: #808080;">{{ time2 }}</view>
				<view v-if="time2 != '请选择开始时间'">{{ time2 }}</view>
				<image class="go" src="../../static/image/go1.png" mode=""></image>
			</view>
			<view @tap="times3()" class="list">
				<view>结束时间 :</view>
				<view v-if="time3=='请选择结束时间'" style="color: #808080;">{{ time3 }}</view>
				<view v-if="time3 !='请选择结束时间'">{{ time3 }}</view>
				<image class="go" src="../../static/image/go1.png" mode=""></image>
			</view>
		</view>
		<view class="btn p30">
			<button @tap="send()" class="btnbg br42">确认修改</button>
		</view>
		<!-- 选择时间 -->
		<w-picker v-if="taimeArr1 != ''" mode="selector" @confirm="onConfirm1" ref="time" themeColor="#ff7c39" :selectList="taimeArr1"></w-picker>
		<!-- 开始时间 -->
		<wPickers mode="time" defaultVal="09:30" :current="false" :hasSecond="false" @confirm="onConfirm2" ref="time2" step="1"></wPickers>
		<!-- 结束时间 -->
		<wPickers mode="time" defaultVal="21:30" :current="false" :hasSecond="false" @confirm="onConfirm3" ref="time3" step="1"></wPickers>
	</view>
</template>

<script>
	import {
		updateStoreInfo
	} from '@/api/api.js'
	import wPicker from '@/components/w-picker/w-picker.vue';
	import wPickers from '@/components/w-pickers/w-picker.vue';
	import {
		datas1
	} from '../shopNews/data.js';
	export default {
		components: {
			wPicker,
			wPickers
		},
		data() {
			return {
				taimeArr1: datas1,
				time1: '请选择营业日期',
				time2: '请选择开始时间',
				time3: '请选择结束时间',
				shakeState: 0,
				txt: ''
			}
		},
		methods: {
			// 选择 日期
			onConfirm1(e) {
				this.time1 = e.result;
			},
			// 选择 日期
			onConfirm2(e) {
				this.time2 = e.result;
			},
			// 选择 日期
			onConfirm3(e) {
				this.time3 = e.result;
			},
			times() {
				this.$refs['time'].show();
			},
			times2() {
				this.$refs['time2'].show();
			},
			times3() {
				this.$refs['time3'].show();
			},
			async send() {

				try {
					if (this.time1 == '请选择营业日期') throw '请选择营业日期'
					if (this.time2 == '请选择开始时间') throw '请选择开始时间'
					if (this.time3 == '请选择结束时间') throw '请选择结束时间'
				} catch (e) {
					uni.showToast({
						title: e,
						icon: 'none'
					})
					return
				}
				let data = {
					"businessHours": this.time1+this.time2+" - "+this.time3
				}
				if (this.shakeState == 0) {
					this.shakeState = 1
					let state = await updateStoreInfo(data)
					if (state.code == 0) {
						this.shakeState = 0
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
					}
				} else {
					this.shakeState = 0
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	@import '../shopNews/index.less';
	@import '../mobile/index.less';
</style>
